import App from './App'
import { createSSRApp } from 'vue'

// 导入并执行utils.js
import '@/utils/utils.js'

// 导入pinia
import { createPinia } from 'pinia'
// 导入pinia持久化插件
// import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createPersistedState } from 'pinia-plugin-persistedstate'

export function createApp() {
  const app = createSSRApp(App)
  // 创建一个pinia插件对象
  const pinia = createPinia()
  // 在pinia对象中使用持久化插件
  // pinia.use(piniaPluginPersistedstate)
  pinia.use(
    createPersistedState({
      key: (id) => `__shenling__${id}`,
      storage: {
        getItem: (key) => {
          return uni.getStorageSync(key)
        },
        setItem: (key, value) => {
          uni.setStorageSync(key, value)
        },
      },
    })
  )
  // 注册pinia插件对象
  app.use(pinia)
  return {
    app,
  }
}
